Last updated: 2024-04-04
Checks: 7 0
Knit directory: RA_SingleCellAnalysis/
This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20240328) was run prior to running
the code in the R Markdown file. Setting a seed ensures that any results
that rely on randomness, e.g. subsampling or permutations, are
reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version 30426ff. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for
the analysis have been committed to Git prior to generating the results
(you can use wflow_publish or
wflow_git_commit). workflowr only checks the R Markdown
file, but you know if there are other scripts or data files that it
depends on. Below is the status of the Git repository when the results
were generated:
Ignored files:
Ignored: .Rproj.user/
Ignored: analysis/figure/
Ignored: data/cellbender_data_h5/
Ignored: output/00_sce_DataPreparation.rds
Unstaged changes:
Modified: analysis/01_Preprocessing.Rmd
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
These are the previous versions of the repository in which changes were
made to the R Markdown (analysis/00_DataPreparation.Rmd)
and HTML (docs/00_DataPreparation.html) files. If you’ve
configured a remote Git repository (see ?wflow_git_remote),
click on the hyperlinks in the table below to view the files as they
were in that past version.
| File | Version | Author | Date | Message |
|---|---|---|---|---|
| html | fa0211e | sarloet | 2024-04-04 | Build site. |
| Rmd | d41ba14 | sarloet | 2024-04-03 | fix |
| html | bc77174 | sarloet | 2024-04-03 | Build site. |
| Rmd | 8543968 | sarloet | 2024-04-03 | fix |
| Rmd | 960ebd0 | sarloet | 2024-04-03 | fix |
| Rmd | eb121be | sarloet | 2024-04-03 | fix |
| html | ef4c495 | sarloet | 2024-04-02 | Build site. |
| Rmd | 9e3e00a | sarloet | 2024-04-02 | commit changes |
| Rmd | d291fd3 | sarloet | 2024-04-02 | initial commit |
| html | d291fd3 | sarloet | 2024-04-02 | initial commit |
#Load Packages
suppressPackageStartupMessages({
library(BiocParallel)
library(ggplot2)
library(dplyr)
library(DropletUtils)
library(scater)
})
set.seed(100)
bpp <- BiocParallel::MulticoreParam(parallel::detectCores()-1)
path <- here::here()
View the CellRanger html report output for each sample
View the CellBender html report output for each sample
Load in the filtered feature barcode matrices from Cellbender of each sample and save them as sce object.
## RA DATASET
rawdata_folder <- paste0(path,"/data/cellbender_data_h5/")
#Get file names
filenames <- list.files(rawdata_folder ,recursive = F, full.names = F,pattern = "\\_filtered.h5$")
filepaths <- paste(rawdata_folder,filenames,sep = "")
#Load data as sce object
sce<-read10xCounts(samples = filepaths, sample.names = filenames,col.names=T,type="HDF5")
colData(sce)$Sample = sub("\\_w_introns.*", "", sub("cellbender_output_", "", as.character(colData(sce)$Sample)))
sce
class: SingleCellExperiment
dim: 36601 119652
metadata(1): Samples
assays(1): counts
rownames(36601): ENSG00000243485 ENSG00000237613 ... ENSG00000278817
ENSG00000277196
rowData names(3): ID Symbol Type
colnames(119652): 1_AAGTACCGTCTCTCAC-1 1_GACTCTCAGGTAACTA-1 ...
17_AGGTGTTGTGGCATCC-1 17_GCCAGCACACAAGTGG-1
colData names(2): Sample Barcode
reducedDimNames(0):
mainExpName: NULL
altExpNames(0):
#Metadata path
metadata_folder <- paste0(path,"/data/metadata/Metadata_Master.csv")
#Load metadata
metadata_df <-read.csv(metadata_folder, header=TRUE, sep=",")
metadata_df
#Add metadata to sce
colData(sce) <- dplyr::left_join(as.data.frame(colData(sce)),
metadata_df,
by= c("Sample" = "orig.ident"),
suffix=c(".x",".y")) %>%
#dplyr::select(Sample, Barcode, Diagnosis, sex, Age, Joint.Location, protocol, Pathotype,Krenn total score,) %>%
dplyr::select(-one_of("Comments")) %>% #select all except
DataFrame(row.names=colnames(sce))
#make row and col names unique
colnames(sce) <- paste0(sce$Sample, ".", sce$Barcode)
rownames(sce) <- paste0(rowData(sce)$ID, ".", rowData(sce)$Symbol)
Dimensions of the count matrix
#Dimensions of count matrix
dim(sce)
[1] 36601 119652
#Feautures/row data
data.frame(colData(sce))
#Droplet details / row data
data.frame(rowData(sce))
Show the number of cells detected in each sample or joint location before filtering
#Histogramm with number of cells per sample
ggplot(colData(sce), aes(x=Sample))+geom_bar()+ coord_flip()+ ggtitle("Number of cells per sample")

data.frame(as.list(table(colData(sce)$Sample)))
#Histogramm with number of cells per sample
ggplot(colData(sce), aes(x=Joint.Location))+geom_bar()+ coord_flip()+ ggtitle("Number of cells per sample")

| Version | Author | Date |
|---|---|---|
| bc77174 | sarloet | 2024-04-03 |
data.frame(as.list(table(colData(sce)$Joint.Location)))
This plot shows cell counts per sample / count occurrence
#Number of genes detected per cell
#Total UMI for a gene versus the number of times detected
genesPerCell <- colSums(counts(sce) > 0)
plot(density(genesPerCell), xlab="Genes per cell", main="Number of genes detected per cell")

This plot gives an idea about the sequencing depth and if the sequencing has reached saturation or not. Plotted is the total gene count across all cells (x-axis) vs Proportion of cells the gene is detected in (y-axis) where each dot represents a gene.
#transcript_capture_efficiency
#Total UMI for a gene versus the number of times detected
tmpCounts <- counts(sce)
plot(rowSums(tmpCounts),
rowMeans(tmpCounts > 0),
log = "x",
xlab="total number of UMIs",
ylab="proportion of cells expressing the gene",
main="Total UMI for a gene vs times detected")

The most strongly and commonly expressed genes expected among all cells are ribosomal and mitochondrial.
#Distribution of counts for the top 20 genes across cells
#rel_expression <- t( t(tmpCounts) / colSums(tmpCounts)) * 100
#rownames(rel_expression) <- rowData(sce)$Symbol
#most_expressed <- sort(rowSums( rel_expression ), decreasing = T)[20:1] ##
#plot_data <- as.matrix(t(rel_expression[names(most_expressed),]))
#boxplot(plot_data, cex=0.1, las=1, xlab="% total count per cell", horizontal=TRUE, main="Distribution of counts for the top 20 genes before filtering")
#rm(tmpCounts)
plotHighestExprs(sce,n = 25)
saveRDS(sce, file =paste0(path,'/output/00_sce_DataPreparation.rds'))
sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; LAPACK version 3.10.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
time zone: Etc/UTC
tzcode source: system (glibc)
attached base packages:
[1] stats4 stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] scater_1.28.0 scuttle_1.10.3
[3] DropletUtils_1.20.0 SingleCellExperiment_1.22.0
[5] SummarizedExperiment_1.30.2 Biobase_2.60.0
[7] GenomicRanges_1.52.1 GenomeInfoDb_1.36.4
[9] IRanges_2.34.1 S4Vectors_0.38.2
[11] BiocGenerics_0.46.0 MatrixGenerics_1.12.3
[13] matrixStats_1.2.0 dplyr_1.1.4
[15] ggplot2_3.5.0 BiocParallel_1.34.2
[17] workflowr_1.7.1
loaded via a namespace (and not attached):
[1] bitops_1.0-7 gridExtra_2.3
[3] rlang_1.1.3 magrittr_2.0.3
[5] git2r_0.33.0 compiler_4.3.1
[7] getPass_0.2-4 DelayedMatrixStats_1.22.6
[9] callr_3.7.3 vctrs_0.6.5
[11] stringr_1.5.1 pkgconfig_2.0.3
[13] crayon_1.5.2 fastmap_1.1.1
[15] XVector_0.40.0 labeling_0.4.3
[17] utf8_1.2.4 promises_1.2.1
[19] rmarkdown_2.26 ps_1.7.5
[21] ggbeeswarm_0.7.2 xfun_0.43
[23] zlibbioc_1.46.0 cachem_1.0.8
[25] beachmat_2.16.0 jsonlite_1.8.8
[27] highr_0.10 later_1.3.2
[29] rhdf5filters_1.12.1 DelayedArray_0.26.7
[31] Rhdf5lib_1.22.0 irlba_2.3.5.1
[33] parallel_4.3.1 R6_2.5.1
[35] bslib_0.5.1 stringi_1.8.3
[37] limma_3.56.2 jquerylib_0.1.4
[39] Rcpp_1.0.12 knitr_1.45
[41] R.utils_2.12.3 httpuv_1.6.15
[43] Matrix_1.6-5 tidyselect_1.2.1
[45] rstudioapi_0.15.0 abind_1.4-5
[47] yaml_2.3.8 viridis_0.6.4
[49] codetools_0.2-19 processx_3.8.2
[51] lattice_0.21-8 tibble_3.2.1
[53] withr_3.0.0 evaluate_0.23
[55] pillar_1.9.0 whisker_0.4.1
[57] generics_0.1.3 rprojroot_2.0.4
[59] RCurl_1.98-1.14 sparseMatrixStats_1.12.2
[61] munsell_0.5.0 scales_1.3.0
[63] glue_1.7.0 tools_4.3.1
[65] BiocNeighbors_1.18.0 ScaledMatrix_1.8.1
[67] locfit_1.5-9.9 fs_1.6.3
[69] rhdf5_2.44.0 grid_4.3.1
[71] edgeR_3.42.4 colorspace_2.1-0
[73] GenomeInfoDbData_1.2.10 beeswarm_0.4.0
[75] BiocSingular_1.16.0 HDF5Array_1.28.1
[77] vipor_0.4.7 cli_3.6.2
[79] rsvd_1.0.5 fansi_1.0.6
[81] viridisLite_0.4.2 S4Arrays_1.0.6
[83] gtable_0.3.4 R.methodsS3_1.8.2
[85] sass_0.4.9 digest_0.6.35
[87] ggrepel_0.9.5 dqrng_0.3.2
[89] farver_2.1.1 htmltools_0.5.6
[91] R.oo_1.26.0 lifecycle_1.0.4
[93] here_1.0.1 httr_1.4.7